package com.ali.framework.common;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsAutoIncrement;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;


/**
 * ActiveRecord实体Base父类
 * @author mileswan
 */
@Setter
@Getter
public class BaseSuperAutoPkDO<T extends Model<?>> extends Model<T> {
    /**
	 * 
	 */
	private static final long serialVersionUID = -2227789894296384768L;
	/**
     * 主键ID
     */
	@TableId(value = "id", type = IdType.AUTO)
    @Column(name = "id", comment = "自增id")
    @IsNotNull
    @IsKey
    @IsAutoIncrement
    protected Long id;
    
	/**
	 * 创建时间
	 */
	@TableField(value = "gmt_create", fill = FieldFill.INSERT)
	@Column(name = "gmt_create", type = MySqlTypeConstant.DATETIME, comment = "创建时间")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	protected LocalDateTime gmtCreate;
	/**
	 * 更新时间
	 */
	@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
	@Column(name = "gmt_modified", type = MySqlTypeConstant.DATETIME, comment = "更新时间")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	protected LocalDateTime gmtModified;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
